package cn.sdhuijin.vms.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name = "t_user")
public class User extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@NotBlank(message = "登录账号不能为空")
	@Column(unique = true, updatable = false)
	private String username;
	@NotBlank(message = "真实姓名不能为空")
	private String realname;
	@Length(max = 11, min = 11, message = "手机号码必须为11位")
	@Column(unique = true)
	private String phone;
	@OneToMany(fetch = FetchType.EAGER)
	private List<Role> roles;
	private String password;

	@ManyToOne
	@JoinColumn(name = "org_id")
	private Organization organization;

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	@Override
	public String toString() {
		return this.realname;
	}

}
